package test.temple;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;

import com.weight.common.generate.base.CommonUtil;
import com.weight.common.generate.base.JavaFile;
import lombok.extern.slf4j.Slf4j;

/**
* 
*  
*/
public class ServiceClassFileMapper extends JavaFile {
	private String model;
	public ServiceClassFileMapper(String filePath, String mainPackage, String curPackage, String model,String tableCnName,List<String> fieldENList) {
		super(filePath, getClassName(model).append(".java").toString(), mainPackage+"."+curPackage, CLASS_TYPE, getClassName(model).toString());
		this.model = model;
		List<String> imports = new LinkedList<String>();
		List<String> classAnnotations = new LinkedList<String>();
		List<String> extendss = new LinkedList<String>();
		List<String> importPackagePaths = new LinkedList<String>();
		List<JavaFile.Field> fieldLists = new LinkedList<Field>();
		List<Method> methodLists = new LinkedList<Method>();
		
		//imports
		imports.add(getImportName(mainPackage, model).toString());
		imports.add(new StringBuilder().append(mainPackage).append(".").append("service").append(".").append(getModelClass(model)).append("Service").toString());
		imports.add(new StringBuilder().append(mainPackage).append(".").append("DAO").append(".").append(getModelClass(model)).append("Mapper").toString());
		imports.add("java.util.List");
		imports.add("java.util.Map");
		imports.add("org.springframework.beans.factory.annotation.Autowired");
		imports.add("org.springframework.stereotype.Service");
		imports.add("com.github.pagehelper.PageHelper");
		imports.add("org.springframework.transaction.annotation.Transactional"); 
		imports.add("com.weight.common.util.CommonUtils");
		imports.add("lombok.extern.slf4j.Slf4j");

		
		
		//classAnnotations
		classAnnotations.add("Service");
		classAnnotations.add("Transactional");
		classAnnotations.add("Slf4j");
		//importPackagePaths
		importPackagePaths.add(new StringBuilder().append(getModelClass(model)).append("Service").toString());
		
//		@Autowired
//		MenuInfoMapper menuInfoMapper;
		List<String> fannotations = new LinkedList<String>();
		fannotations.add("Autowired");
		String fmodifier = "private";
		String ftype = new StringBuilder().append(getModelClass(model)).append("Mapper").toString();
		String fname = new StringBuilder(model).append("Mapper").toString();
		String value = null;
		Field field = new Field(fannotations, fmodifier , ftype, fname, value);
		fieldLists.add(field);
		//methodLists
		CommonUtil.insertMethod(methodLists,model,tableCnName,true,true,fieldENList);
		/**	类注释	*/
		Collection<String> classDescriptionList=CommonUtil.descriptionModel(new StringBuilder(tableCnName), null, false);
		super.init(imports, classAnnotations, extendss, importPackagePaths, fieldLists, methodLists,classDescriptionList);
	}
	 
 
	public static StringBuilder getClassName(String model) {
		StringBuilder className = new StringBuilder();
		className.append(getModelClass(model));
		className.append("ServiceImpl");
		return className;
	}
	
	public static StringBuilder getImportName(String packagePath,String and,String name) {
		StringBuilder importName = new StringBuilder();
		importName.append(packagePath);
		importName.append(".");
		importName.append(and);
		importName.append(".");
		importName.append(name);
		return importName;
	}
	
}
